﻿using Architecture.API.Application.TraceabilityCommand.SlaughterCommand;
using MediatR;
using Traceability.Domain.Service.SlaughterServices;
using Traceability.Domain.SlaughterDomain;

namespace Architecture.API.Application.TraceabilityCommandHandler.SlaughterCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class UpdateSlaughterCommandHandler : IRequestHandler<UpdateSlaughterCommand, int>
    {
        /// <summary>
        /// 屠宰服务
        /// </summary>
        protected readonly ISlaughterService slaughterService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="slaughterService">屠宰服务</param>
        public UpdateSlaughterCommandHandler(ISlaughterService slaughterService)
        {
            this.slaughterService = slaughterService;
        }

        /// <summary>
        /// 修改屠宰信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(UpdateSlaughterCommand request, CancellationToken cancellationToken)
        {
            return await slaughterService.UpdateSlaughter(new Slaughter() { SlaughterId=request.SlaughterId,Batch=request.Batch,AveWeight=request.AveWeight,ArriveDate=request.ArriveDate,SlaughterTime=request.SlaughterTime,ShoppingId=request.ShoppingId,CreatedBy=request.CreatedBy,CreatedDate=request.CreatedDate, UpdatedBy=request.UpdatedBy,UpdatedDate=DateTime.Now,DeletedBy=request.DeletedBy,DeletedDate=request.DeletedDate,IsDeleted=request.IsDeleted });
        }
    }
}
